using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.ComponentModel;

namespace BPMVE_XPDL_Library
{
    /// <summary>
    /// 7.6.5.3.6. TaskSend
    /// A TaskType of Send MUST NOT have an incoming Message Flow.
    /// A Send Task is a Simple Task that is designed To send a Message To an external participant 
    /// (relative To the Business Process). Once the Message has been sent, the Task is Completed.
    /// </summary>
    public class TaskSend : IValidate
    {
        /// <summary>
        /// A Message for the Message attribute should be entered as implementation detail. This
        /// indicates that the Message will be sent by the Task. The Message in this context is
        /// equivalent To an out-only Message pattern (Web Service). One OR more corresponding 
        /// outgoing Message Flow MAY be shown on the diagram. However, the display of the Message
        /// Flow is not required. The Message is applied To All outgoing Message Flow AND the 
        /// Message will be sent down All outgoing Message Flow at the completion of a single 
        /// instance of the Task. See section 7.9.4
        /// </summary>
        [XmlElement("Message")]
        public Message Message { get; set; }
		[XmlIgnore]
		public bool MessageSpecified { get { return Message != null; } }

        /// <summary>
        /// Describes the web services operation To be used by this task. See section 7.9.6.
        /// </summary>
        [XmlElement("WebServiceOperation")]
        public WebServiceOperation WebServiceOperation{ get; set; }
		[XmlIgnore]
		public bool WebServiceOperationSpecified { get { return WebServiceOperation != null; } }

        /// <summary>
        /// Describes how To process faults generated by the web Service operation in this task.
        /// See section 7.9.7.
        /// </summary>
        [XmlArray("WebServiceFaultCatch")]
        public List<WebServiceFaultCatch> WebserviceFaultCatch { get; set; }
		[XmlIgnore]
		public bool WebserviceFaultCatchSpecified { get { return WebserviceFaultCatch == null ? false : WebserviceFaultCatch.Count != 0; } }

        /// <summary>
        /// WebService | Other | Unspecified
        /// </summary>
        [XmlAttribute("Implementation")]
        [DefaultValue(ImplementationEnum.WebService)]
        public ImplementationEnum Implementation { get; set; }
        //[XmlIgnore]
        //public bool ImplementationSpecified { get { return Implementation != null; } }




        public TaskSend()
        {
            Implementation = ImplementationEnum.WebService;
        }

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		public override bool Equals(object obj)
        {
            TaskSend value = obj as TaskSend;
            if (value != null)
            {
                List<object> listA = new List<object>
                {
                    this.Implementation, this.Message, this.WebServiceOperation
                };

                List<object> listB = new List<object>
                {
                    value.Implementation, value.Message, value.WebServiceOperation
                };

                if (!Utilities.IsListEqual<WebServiceFaultCatch>(this.WebserviceFaultCatch, value.WebserviceFaultCatch))
                    return false;

                return (Utilities.IsEqual(listA, listB));
            }

            return false;
        }

        #region IValidate Members

        public bool Validate()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}